#include<iostream>

class Solution {
public:

    int getPow(int num)
    {
        int count = 0;
        while (num)
        {
            count += pow(num % 10, 2);
            num /= 10;
        }
        return count;
    }
    bool isHappy(int n) {
        int slow = n, fast = n;
        while (true)
        {
            slow = getPow(slow);
            fast = getPow(getPow(fast));
            if (slow == fast && slow == 1) return true;
            if (slow == fast && slow != 1) return false;
        }
    }
};


int main()
{
    int num = 19;
    Solution s;
    s.isHappy(num);
    return 0;
}